extends Node
class_name AmmoHandler

@onready var weapon_manager: Node3D = $"../WeaponManager"
#@onready var label_ammo: Label = %Label_Ammo ##就绪时才赋值
@export var label_ammo: Label
func _ready() -> void:
	pass
enum TYPE_AMMO {
	BULLET_COMMON,
	BULLET_LAEGE
}

var ammo_storage := {
	TYPE_AMMO.BULLET_COMMON : 100,
	TYPE_AMMO.BULLET_LAEGE : 50 
}


func has_ammo(type: TYPE_AMMO) -> bool:
	return ammo_storage[type] > 0

func use_ammo(type: TYPE_AMMO) -> void:
	if has_ammo(type):
		ammo_storage[type] -= 1
		update_ammo_label(type)
func add_ammo(type: TYPE_AMMO,amount: int) -> void:
	ammo_storage[type] += amount
	for child in weapon_manager.get_children():
		if child.visible == true:
			if child.TYPE_AMMO == type:
				update_ammo_label(type)				
func update_ammo_label(type: TYPE_AMMO) -> void:
	label_ammo.set_text( str(ammo_storage[type]))
